package org.example.server.user.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.server.user.bean.AccountBean;
import org.example.server.user.bean.ResultBean;
import org.example.server.user.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class AccountController {

    @Autowired
    private AccountService accountService;
    @RequestMapping("/register")
    public ResultBean register(@RequestBody AccountBean accountBean) {
        try {
            accountService.register(accountBean);
            return new ResultBean(200,"注册成功",null);
        }catch (Exception e) {
            return new ResultBean(500, e.getMessage(), null);
        }
    }

    @RequestMapping("/login")
    public ResultBean login(@RequestBody AccountBean accountBean) {
        log.info("account,用户登录,请求参数:{}",accountBean);
        try {
            String id = accountService.login(accountBean);
            log.info("account,用户登录,完成");
            return new ResultBean(200,"登录成功",id);
        }catch (Exception e) {
            return new ResultBean(500,e.getMessage(),null);
        }
    }
}
